package com.google.code.alpaca.prototype.handler;

import javax.inject.Inject;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.google.code.alpaca.prototype.dao.MessageDAO;
import com.google.code.alpaca.prototype.rpc.MessageActions.GetAllMessagesAction;
import com.google.code.alpaca.prototype.rpc.MessageListResult;
import com.google.inject.persist.Transactional;
import com.google.inject.servlet.RequestScoped;

@RequestScoped
public class GetAllMessagesHandler implements
		ActionHandler<GetAllMessagesAction, MessageListResult> {

	@Inject
	private MessageDAO messageRepository;
	
	public GetAllMessagesHandler() {
		System.out.println("lalala");
	}

	@Override
	public Class<GetAllMessagesAction> getActionType() {
		return GetAllMessagesAction.class;
	}

	@Transactional
	@Override
	public MessageListResult execute(GetAllMessagesAction action,
			ExecutionContext context) throws DispatchException {
		System.out.println(messageRepository);
		MessageListResult result = new MessageListResult(
				messageRepository.getAll());
		return result;
	}

	@Override
	public void rollback(GetAllMessagesAction action, MessageListResult result,
			ExecutionContext context) throws DispatchException {
	}

}
